package com.qlm.interceptor;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Enhancer;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.qlm.common.Define;
import com.qlm.tools.CustomerIPUtil;
import com.qlm.view.AdminView;
/**
 * 记录操作日志拦截器
 * @author Administrator
 *
 */
public class AdminOperateInterceptor implements Interceptor{
	protected final static Logger       logger = LoggerFactory.getLogger(AdminOperateInterceptor.class);
	
	@Override
	public void intercept(Invocation inv) {		
		AdminView operating = null;
		//操作IP
		String ipAddr = CustomerIPUtil.getIpAddr(inv.getController().getRequest());
		if(ipAddr.equals("0:0:0:0:0:0:0:1")){
			ipAddr = "127.0.0.1";
		}
		operating = inv.getController().getSessionAttr("adminView");
		if(operating == null){
			operating = new AdminView();
		}
		int roleId = operating.getRoleId();
		String op =inv.getMethodName();
		if(Define.ROLE_ADMIN == roleId){//普通管理员
			if( "qrCodeAdd".equals(op) || "setValid".equals(op)){
				return;//没有权限
			} 
		}else if(Define.ROLE_MANAGE == roleId){//超级管理员
			if("qrCodeAdd".equals(op)){
				return;//没有权限
			} 
		}
		inv.invoke();

	}
}
